package com.general.message.notice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.general.message.notice.entity.NoticeInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface NoticeInfoMapper  extends BaseMapper<NoticeInfo> {

    //联表查询消息通知和消息路由
    @Select("select a.*,b.web_route,b.mobile_route from msg_notice_info a,msg_notice_route b where a.menu_key = b.menu_key and a.has_read = '0' and a.receive_user = #{userId}")
    public IPage<NoticeInfo> getAllInfo(Page<NoticeInfo> page,@Param("userId") Long userId);


    //联表查询有单菜单权限待通知用户
    @Select("select user_id from sys_user_role where role_id in (select role_id from sys_role_menu where menu_id = #{menuId})")
    public List<String> getUserList(@Param("menuId") String menuId);

    //联表查询有多菜单权限的用户
    @Select("<script>" +
            "select distinct user_id from sys_user_role where role_id in " +
                "(select distinct role_id from sys_role_menu where menu_id in " +
            "<foreach item='item' index='index' collection='menuIdList' open='(' separator=',' close=')'>"+
                "#{item}"+
            "</foreach>"+
            ")"+
            "</script>"
    )
    public List<String> getUserLists(@Param("menuIdList") List<String> menuIdList);
}
